.PHONY: build clean install help

# Default target
.DEFAULT_GOAL := help

# Build directory
BUILD_DIR := build
BIN_DIR := bin

# Compiler settings
CXX := g++
CMAKE := cmake
CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=Release

help:
	@echo "YOLOv8 OpenVINO C++ Build Targets:"
	@echo "  make build       - Build the project"
	@echo "  make clean       - Clean build artifacts"
	@echo "  make rebuild     - Clean and build"
	@echo "  make install     - Install binaries to /usr/local/bin"
	@echo "  make help        - Show this help message"

build: $(BUILD_DIR)
	@echo "Building YOLOv8 OpenVINO inference..."
	cd $(BUILD_DIR) && $(CMAKE) .. $(CMAKE_FLAGS) && make -j$$(nproc)
	@mkdir -p $(BIN_DIR)
	@cp $(BUILD_DIR)/detect $(BIN_DIR)/
	@cp $(BUILD_DIR)/detect_service $(BIN_DIR)/
	@echo "Build completed. Binaries in $(BIN_DIR)/"

$(BUILD_DIR):
	@mkdir -p $(BUILD_DIR)

clean:
	@echo "Cleaning build artifacts..."
	@rm -rf $(BUILD_DIR)
	@rm -rf $(BIN_DIR)
	@echo "Clean completed."

rebuild: clean build

install: build
	@echo "Installing binaries..."
	@sudo install -m 755 $(BIN_DIR)/detect /usr/local/bin/
	@sudo install -m 755 $(BIN_DIR)/detect_service /usr/local/bin/
	@echo "Installation completed."

